<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous" />
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div class="container-fluid" id="app">
    <div class="row">
        <div class="col-md-12 text-center" style="background-color: red; color: white" >
            <h3>蜗牛书店</h3>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <ol class="breadcrumb">
                <li v-for="bt in typelist"><a href="javascript:void(0)" :href="'/book/showBookView/?typeid='+bt.id" v-text="bt.name"></a></li>
            </ol>
        </div>

        <div class="col-md-3">
            <form class="form-inline">
                <div class="form-group">
                    <label for="search" class="sr-only">请输入关键词</label>
                    <input type="text" class="form-control" v-model="searchName" id="search" placeholder="请输入关键词">
                </div>
                <button type="button" @click.prevent="search" class="btn btn-default">搜索</button>
            </form>
        </div>

        <div class="col-md-3">
            <span v-if="account == ''">
                        <a class="btn btn-success" th:href="@{/login.html}">登录</a>
                        <a class="btn btn-primary" th:href="@{/reg.html}">注册</a>
                    </span>

            <span v-if="account != ''">
                        欢迎您: {{account}}  &nbsp;&nbsp;
                        <a class="btn btn-primary" href="">退出</a>
                    </span>

            <button type="button" class="btn btn-default btn-sm">个人中心</button>
            <a  class="btn btn-default btn-sm" th:href="@{/cart.html}">我的购物车</a>
            <a  class="btn btn-default btn-sm" th:href="@{/order.html}">我的订单</a>
        </div>
    </div>

    <div class="row">
        <div class="container">
            <div  v-for="o in orderList">
                <div class="row" style="height: 40px ;line-height: 40px">
                    <div class="col-md-12">
                        <p style="background-color: #CCCCCC; font-size: 15px; line-height: 40px">订单编号:{{o.orderNum}} 下单时间:{{o.createtime}}</p>
                    </div>
                </div>
                <div class="row p-3">
                    <div class="col-md-10 col-md-offset-1">
                        <table class="table">
                            <tr>
                                <th>图片</th>
                                <th>名称</th>
                                <th>购买数量</th>
                                <th>金额</th>
                            </tr>
                            <tr v-for="i in o.lists">
                                <td>
                                    <img style="height: 60px;width: 60px" :src="i.bookSrc">
                                </td>
                                <td v-text="i.bookName" style="vertical-align: middle">名称</td>
                                <td v-text="i.buyCount" style="vertical-align: middle">购买数量</td>
                                <td v-text="i.sumPrice" style="vertical-align: middle">金额</td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-1">
                        <p v-if="o.state == 1">
                            <button class="btn btn-primary" @click="pay(o.id)">去支付</button>
                            <button class="btn btn-primary" @click="cancelOrder(o.id)">取消</button>
                        </p>
                        <p v-if="o.state == 2">
                            <button class="btn btn-primary" @click="backMoney(o.id)">退款</button>
                        </p>

                        <p v-if="o.state == 3">
                            <button class="btn btn-primary">退款中...</button>
                        </p>

                        <p v-if="o.state == 4">
                            <button class="btn btn-primary">已退款</button>
                        </p>

                        <p v-if="o.state == 5">
                            <button class="btn btn-primary">已取消</button>
                        </p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-2 col-md-offset-5">
                <button class="btn btn-primary">上一页</button> &nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-primary">下一页</button>
            </div>
        </div>
    </div>
</div>

<script>
    let vueApp = new Vue({
        el:"#app",
        data:{
            typelist:[],
            orderList:[],
            account:''
        },
        methods:{
            searchName(){

            },
            initBookType(){
                let _this = this ;
                let url = "/home/typeList" ;
                $.get(url,function (data){
                    console.log(data);
                    _this.typelist = data ;
                },"json")
            },
            initMyOrder(){
                let _this = this ;
                let url = "/order/orderList" ;
                $.get(url,function (data){
                    console.log(data);
                    _this.orderList = data.records ;
                },"json")
            },
            //获取用户名
            getAccount(){
                let url = "/user/getAccount" ;
                let _this = this ;
                $.get(url,function (data){
                    _this.account = data ;
                })
            },
            cancelOrder(oid){
                console.log("oid------------>"+oid);
                let _this = this ;
                let url = "/order/cancelOrder?oid="+id;
                $.get(url,function (data){
                    if(data == 'ok') {
                        alert("取消成功!");
                        _this.initMyOrder();
                    }else {
                        alert(data);
                    }
                })
            },
            pay(oid){

            },
            backMoney(oid){

            }
        },
        created(){
            this.initBookType();
            this.initMyOrder();
            this.getAccount();
        }
    })
</script>
</body>
</html>